/*Analyze the confidence (really our imputed subjective probability of a correct
response) from the non-expert experiments. Using 0.33/0.67 as the cutoffs for
confident/not confident, use the midpoints of the four corresponding intervals
as people's beliefs on the probability of a discontinuity. (So people's probabilities
will either be (0.5+0.67)/2 or (0.67+1)/2. Create figures.
*/

cap log close
log using "${logs}/confidence_analysis.log", replace	
 
set scheme s1mono

use "${dat}/confidence.dta", clear

*DGP specific graphs:
levelsof phase, local(levels) 
local count = 1
foreach l of local levels{
preserve
keep if phase == "`l'"

	twoway (connected confidence_midpoints abs_disc if playertreatment_group == "A", msymbol(Oh)) ///
	(connected confidence_midpoints abs_disc if playertreatment_group == "B", msymbol(Th)) ///
	(connected confidence_midpoints abs_disc if playertreatment_group == "C", msymbol(Dh)) ///
	(connected confidence_midpoints abs_disc if playertreatment_group == "D", msymbol(Sh)), ///
	ytitle("") xtitle("")  legend(lab (1 "A") lab(2 "B") lab(3 "C") lab(4 "D")) title("RDD Phase `count'", size(medsmall)) ///
	ylab(0 (.2) 1) yscale(range(0 1)) ///
 name(graph`count', replace) 
 
graph export "${output}/confidence_midpoints_stata_phase`count'.pdf", as(pdf) replace


local count = `count' + 1
restore

}


graph close _all



 use "${dat}/survey_merged_rd_estimates_micro.dta", clear
 gen confident = playerchosenStakes==1
 gen subj_prob = 0
 replace subj_prob = (1 + 0.67) / 2 if confident == 1
 replace subj_prob = (0.5 + 0.67) / 2 if confident == 0
 collapse (mean) subj_prob, by(phase playertreatment_group abs_disc)

preserve
keep if phase == 1
	twoway (connected subj_prob abs_disc if playertreatment_group == "A", msymbol(Oh)) ///
	(connected subj_prob abs_disc if playertreatment_group == "B", msymbol(Th)) ///
	(connected subj_prob abs_disc if playertreatment_group == "C", msymbol(Dh)) ///
	(connected subj_prob abs_disc if playertreatment_group == "D", msymbol(Sh)), ///
	ytitle("Mean Perceived Prob. Correct") xtitle("")  legend(lab (1 "Small Bins/Normal Scale") lab(2 "Large Bins/Normal Scale") lab(3 "Small Bins/Large Scale") lab(4 "Large Bins/Large Scale")) title("Phase 1", size(medsmall)) ///
	ylab(0.7 (.05) 0.9) yscale(range(0.7 0.9)) ///
 name(graph`count', replace) 
graph export "${output}/subjective_prob_correct_phase1.pdf", as(pdf) replace
restore
 
preserve
keep if phase == 2
	twoway (connected subj_prob abs_disc if playertreatment_group == "A", msymbol(Oh)) ///
	(connected subj_prob abs_disc if playertreatment_group == "B", msymbol(Th)) ///
	(connected subj_prob abs_disc if playertreatment_group == "C", msymbol(Dh)) ///
	(connected subj_prob abs_disc if playertreatment_group == "D", msymbol(Sh)), ///
	ytitle("Mean Perceived Prob. Correct") xtitle("")  legend(lab (1 "Small Bins/Even Spacing") lab(2 "Large Bins/Even Spacing") lab(3 "Small Bins/Quant. Spacing") lab(4 "Large Bins/Quant. Spacing")) title("Phase 2", size(medsmall)) ///
	ylab(0.7 (.05) 0.9) yscale(range(0.7 0.9)) ///
 name(graph`count', replace) 
graph export "${output}/subjective_prob_correct_phase2.pdf", as(pdf) replace
restore

preserve
keep if phase == 3
	twoway (connected subj_prob abs_disc if playertreatment_group == "A", msymbol(Oh)) ///
	(connected subj_prob abs_disc if playertreatment_group == "B", msymbol(Th)) ///
	(connected subj_prob abs_disc if playertreatment_group == "C", msymbol(Dh)), ///
	ytitle("Mean Perceived Prob. Correct") xtitle("")  legend(lab (1 "No Fit Line/Yes Vertical Line") lab(2 "Fit Line/Vertical Line") lab(3 "No Fit Line/No Vertical Line")) title("Phase 3", size(medsmall)) ///
	ylab(0.7 (.05) 0.9) yscale(range(0.7 0.9)) ///
 name(graph`count', replace) 
graph export "${output}/subjective_prob_correct_phase3.pdf", as(pdf) replace
restore

preserve
keep if phase == 6
	twoway (connected subj_prob abs_disc if playertreatment_group == "A", msymbol(Oh)) ///
	(connected subj_prob abs_disc if playertreatment_group == "B", msymbol(Th)) ///
	(connected subj_prob abs_disc if playertreatment_group == "C", msymbol(Dh)) ///
	(connected subj_prob abs_disc if playertreatment_group == "D", msymbol(Sh)), ///
	ytitle("Mean Perceived Prob. Correct") xtitle("")  legend(lab (1 "Small Bins/No Fit Line") lab(2 "Large Bins/No Fit Line") lab(3 "Small Bins/Fit Line") lab(4 "Large Bins/Fit line")) title("Phase 4", size(medsmall)) ///
	ylab(0.7 (.05) 0.9) yscale(range(0.7 0.9)) ///
 name(graph`count', replace) 
graph export "${output}/subjective_prob_correct_phase4.pdf", as(pdf) replace
restore
 
graph close _all

cap log close
